package com.shujia.spark

import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.rdd.RDD

object Demo12MapValues {
  def main(args: Array[String]): Unit = {
    val conf: SparkConf = new SparkConf()
      .setMaster("local")
      .setAppName("Demo10Union")


    val sc = new SparkContext(conf)

    val agesRDD: RDD[(String, Int)] = sc.makeRDD(List(("002", 24), ("003", 25)))


    val mapRDD: RDD[(String, Int)] = agesRDD.map {
      case (name: String, age: Int) =>
        (name, age + 1)
    }

    mapRDD.foreach(println)
    /**
      * mapValues: 支队value 做处理，key不变
      *
      */
    val mapValuesRDD: RDD[(String, Int)] = agesRDD.mapValues(v => v + 1)

    mapValuesRDD.foreach(println)

  }

}
